﻿using Crift;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CriftDemo
{
    public partial class FrmEncrypt : Form
    {
        public FrmEncrypt()
        {
            InitializeComponent();
        }

        private void btnBrowse1_Click(object sender, EventArgs e)
        {
            ofd1.ShowDialog();
        }



        private void ofd1_FileOk(object sender, CancelEventArgs e)
        {
            txtSrcFile.Text = ofd1.FileName;
            txtDestFile.Text = ofd1.FileName + ".ssr";
        }

    

        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            using (FileStream SrcFile = new FileStream(txtSrcFile.Text, FileMode.Open))
            {
                StreamCipher StrCipher = new StreamCipher(txtKey.Text);
                byte[] SrcData = new byte[SrcFile.Length];
                SrcFile.Read(SrcData, 0, SrcData.Length);
                byte[] DestData = StrCipher.Encrypt(SrcData);
                using (FileStream DstFile = new FileStream(txtDestFile.Text, FileMode.Create))
                {
                    DstFile.Write(DestData, 0, DestData.Length);
                }
            }
            MessageBox.Show("Done");
        }

        private void textBox1_Validating(object sender, CancelEventArgs e)
        {

        }
    }
}
